package com.example.juc.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Demo02 {

    public static void main(String[] args) {

        Phone2 phone = new Phone2();

        new Thread(phone::send,"A").start();

        new Thread(phone::send,"B").start();
    }


}

class Phone2 {

    Lock lock = new ReentrantLock();
    public synchronized void send() {
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName() + "->send");
            call();
        }finally {
            lock.unlock();
        }
    }

    public void call(){
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName()+"->call");
        }finally {
            lock.unlock();
        }
    }
}